package cn.cool.config;

import cn.cool.interceptors.JWTLoginInterceptor;
import com.github.binarywang.java.emoji.EmojiConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author LiuH
 * @create 2021-01-24 下午 5:04
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {


    @Bean
    public JWTLoginInterceptor jwtLoginInterceptor(){
        return new JWTLoginInterceptor();
    }

    //emoji转换器放入spring容器
    @Bean
    public EmojiConverter emojiConverter(){
        return EmojiConverter.getInstance();
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtLoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login",
                        "/user/getRegisterCode",
                        "/user/register",
                        "/swagger-resources/**",
                        "/webjars/**",
                        "/v2/**",
                        "/swagger-ui.html/**");
    }
}
